# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=language-server
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.36.2
pkgrel=2
pkgdesc="An implementation of the Language Server Protocol for Python (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/palantir/python-language-server"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-future"
         "${MINGW_PACKAGE_PREFIX}-python-jedi"
         "${MINGW_PACKAGE_PREFIX}-python-jsonrpc-server"
         "${MINGW_PACKAGE_PREFIX}-python-pluggy"
         "${MINGW_PACKAGE_PREFIX}-python-ujson")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-coverage"
              "${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-cov"
              "${MINGW_PACKAGE_PREFIX}-python-pyflakes"
              "${MINGW_PACKAGE_PREFIX}-python-flake8"
              "${MINGW_PACKAGE_PREFIX}-python-flaky"
              #"${MINGW_PACKAGE_PREFIX}-python-autopep8"
              "${MINGW_PACKAGE_PREFIX}-python-rope"
              #"${MINGW_PACKAGE_PREFIX}-python-pydocstyle"
              "${MINGW_PACKAGE_PREFIX}-python-yapf"
              "${MINGW_PACKAGE_PREFIX}-python-pylint"
              "${MINGW_PACKAGE_PREFIX}-python-mock")
source=("python-${_realname}-${pkgver}.tar.gz"::"${url}/archive/${pkgver}.tar.gz"
        "001-python-language-server-0.36.2-fix-versioneer.patch"
        "002-python-language-server-0.36.2-fix-setup.patch")
sha256sums=('fb573f780467c1cae0de47065eecbaaf9b457bd5cbe9f5cf8409224e1cd21cf6'
            'fb52b245c4f59a50ecb5f689eea9fd9a86a8577a5f91a677f1fcb2b4cc262e90'
            'd45d3b1dec94a9033dd13b3754ffe17396e19f1621b26fbc87fe5f84214d0b89')

prepare() {
  cd "${srcdir}/python-${_realname}-${pkgver}"

  patch -p1 -i "${srcdir}/001-python-language-server-0.36.2-fix-versioneer.patch"
  patch -p1 -i "${srcdir}/002-python-language-server-0.36.2-fix-setup.patch"
}

build() {
  cd "${srcdir}"
  rm -rf "python-build-${MSYSTEM}" | true
  cp -r "python-${_realname}-${pkgver}" "python-build-${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"

  msg "Python build for ${MSYSTEM}"
  PYTHONHASHSEED=0 \
  VERSIONEER_OVERRIDE=${pkgver} \
    ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  PYTHONPATH="build/lib" pytest \
    --ignore=test/plugins/test_autopep8_format.py \
    --ignore=test/plugins/test_completion.py \
    --ignore=test/plugins/test_pydocstyle_lint.py \
    --ignore=test/plugins/test_rope_rename.py \
    --ignore=test/plugins/test_yapf_format.py
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  VERSIONEER_OVERRIDE=${pkgver} \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1 --skip-build

  # remove shebang line
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}

# vim: ts=2 sw=2 et:
